//
//  QQImageTool.swift
//  QQ音乐
//
//  Created by 曹均华 on 16/6/5.
//  Copyright © 2016年 曹均华. All rights reserved.
//

import UIKit


class QQImageTool: NSObject {

    
    class func createNewImage(sourceImage: UIImage, str: String) -> UIImage {
        
        let size = sourceImage.size
        // 1. 开启上下文
        UIGraphicsBeginImageContext(size)
        // 2. 绘制大图片
        sourceImage.drawInRect(CGRectMake(0, 0, size.width, size.height))
        
        // 3. 绘制文字
        let paraStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
        paraStyle.alignment = .Center
        
        let attributes: [String : AnyObject] = [
            NSForegroundColorAttributeName: UIColor.whiteColor(),
            NSFontAttributeName: UIFont.systemFontOfSize(26),
            NSParagraphStyleAttributeName:  paraStyle
            
        
        ]
        (str as NSString).drawInRect(CGRectMake(0, 0, size.width, 30), withAttributes: attributes)
        
        // 4. 取出合成图片
        let resultImage = UIGraphicsGetImageFromCurrentImageContext()
        
        // 5. 关闭上下文
        UIGraphicsEndImageContext()
        
        // 6. 返回结果
        return resultImage
        
        
    }
    
    
}
